package com.example.presentshopping.ui.activity

import BaseRecyclerAdapter
import BaseRecyclerHolder
import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import com.example.presentshopping.R
import com.example.presentshopping.config.base.BaseMvpActivity
import com.example.presentshopping.config.bean.SeniorityBean
import com.example.presentshopping.config.bean.SupplierListBean
import com.example.presentshopping.mvp.presenter.PublicPresenter
import com.example.presentshopping.net.http.HttpRequest
import com.example.presentshopping.net.http.HttpURL
import com.example.presentshopping.net.observer.TaskCallback
import com.example.presentshopping.utils.tool.GsonUtils
import kotlinx.android.synthetic.main.activity_seniority.*

class SeniorityActivity : BaseMvpActivity() {

    var baseRecyclerAdapter: BaseRecyclerAdapter<SeniorityBean.DataBean.ListBean>? = null

    var sendMesPresenter: PublicPresenter? = null
    var  seniorityBean: SeniorityBean ?=null
    override val layoutId: Int
        get() = R.layout.activity_seniority

    override fun initView(savedInstanceState: Bundle?) {
        sendMesPresenter = PublicPresenter(this,false, "")
        sendMesPresenter?.attachView(this)
        title_main_tv.leftBackImageTv.setOnClickListener { finish() }
        setAdapter()
        GoodsCategoryList()



    }




    fun setAdapter(){
        baseRecyclerAdapter  =object :BaseRecyclerAdapter<SeniorityBean.DataBean.ListBean> (context,null,R.layout.item_seniority){
            @SuppressLint("SetTextI18n")
            override fun convert(
                holder: BaseRecyclerHolder?,
                data: SeniorityBean.DataBean.ListBean,
                position: Int,
                isScrolling: Boolean,
                selectedPosition: Int
            ) {
              val mobile_tv =holder?.getView<TextView>(R.id.mobile_tv)
              val num_tv =holder?.getView<TextView>(R.id.num_tv)
              val total_tv =holder?.getView<TextView>(R.id.total_tv)
              val Seniority_tv =holder?.getView<TextView>(R.id.Seniority_tv)
                Seniority_tv?.text =(position+1).toString()
                mobile_tv?.text ="用户："+ data.mobile
                num_tv?.text = "拼团次数："+ data.num.toString()
                total_tv?.text ="金额："+data.total
            }
        }
        location_rcv.adapter =baseRecyclerAdapter
    }

    fun GoodsCategoryList(){
        sendMesPresenter?.netWorkRequestPost(
            HttpURL.Req_userIncomeHot,
            HttpRequest.getGoodsDetail(""),object : TaskCallback {
                override fun onSuccess(data: String?) {
                    seniorityBean = GsonUtils.getGson().fromJson(data,SeniorityBean().javaClass)
                    baseRecyclerAdapter?.setData(seniorityBean?.data?.list)
                }

                override fun onFailure(e: Throwable?, code: Int, msg: String?, isNetWorkError: Boolean) {

                }

            })
    }

    override fun onDestroy() {
        sendMesPresenter?.detachView()
        super.onDestroy()
    }


    override fun showToast(msg: String?) {

    }

    override fun onSuccess(data: String?) {

    }

    override fun onFailure(e: Throwable?, code: Int, msg: String?, isNetWorkError: Boolean) {

    }
}